#include "highpass.h"

highpass::highpass(void)
{
	filter_index = HIGHPASS_FILTER;
	filterLevel = 15;
	scale = 2;
	noErodeDialate = true;

	element = cvCreateStructuringElementEx( 3, 3, 0, 0, CV_SHAPE_ELLIPSE, 0 );
    element2 = cvCreateStructuringElementEx( 5, 5, 2, 2, CV_SHAPE_ELLIPSE, 0 );
}

void highpass::process(IplImage* src, IplImage* des)
{

	IplImage *outra = cvCreateImage( cvGetSize(src), IPL_DEPTH_16S, 1 );
	outra->origin = src->origin;

	IplImage *outra2 = cvCreateImage( cvGetSize(src), IPL_DEPTH_16S, 1 );
	outra2->origin = src->origin;

	cvConvertScale( src, outra );
	//CV_MEDIAN
	cvSmooth( outra, outra2, CV_GAUSSIAN, (filterLevel*2) + 3, (filterLevel*2) + 3, 0, 0 );

	cvSub(outra, outra2, outra2);
	//return;
	if(noErodeDialate)
	{
		cvConvertScale( outra2, des, ((double)scale+1.0),  0);
	    cvErode(des,des,element,1);
		cvSmooth( des, des, CV_GAUSSIAN, 11, 11, 0, 0 );
	    cvDilate(des,des,element,1);
	} else {
		cvConvertScale( outra2, des, ((double)scale+1.0),0);
	    cvErode(des,des,element,2);
		cvSmooth( des, des, CV_GAUSSIAN, 7, 7, 0, 0 );
	    cvDilate(des,des,element2,1);
	    cvDilate(des,des,element,1);
	}

}


highpass::~highpass(void)
{
	cvReleaseStructuringElement(&element);
    cvReleaseStructuringElement(&element2);

}